package com.cjg.winter.common;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;

@Data
public class R {
    private  Integer code;
    private  String message;
    private Map<String,Object> data=new HashMap<>();

    //防止外部直接调用
     private  R(){}

    /**
     * 返回成功的结果
     * @return
     */
     public static R ok(){
         R r=new R();
         r.setCode(ResponseEnum.SUCCESS.getCode());
         r.setMessage(ResponseEnum.SUCCESS.getMessage());
         return  r;
     }
    /**
     * 返回是被的结果
     * @return
     */
    public static R error(){
        R r=new R();
        r.setCode(ResponseEnum.ERROR.getCode());
        r.setMessage(ResponseEnum.ERROR.getMessage());
        return  r;
    }
    /**
     * 返回特定的结果
     * @return
     */
    public static R setResult(ResponseEnum result){
        R r =new R();
        r.setCode(result.getCode());
        r.setMessage(result.getMessage());
        return  r;
    }

    /**
     * 给data赋值, 直接全都返回 R 是因为能够链式编程
     * @return
     */
    public R put(String key ,Object value){
        this.data.put(key,value);
        return  this;
    }


}
